using System;
using System.Collections.Generic;
using System.Text;
using System.IO; 
using System.Xml.XPath;
using System.Xml;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Collections; 

namespace Administration_Toolkit_v2
{
    class Utilities
    {
       
       private static string   strDataElementsXPath = @"/root/data";
       private static string   strMetaDataElementsXPath = @"/root/metadata";
       private static string   strAssemblyElementsXPath = @"/root/assembly";
       private static string   strResHeaderElementsXPath = @"/root/resheader";
       private static string   strNameXPath = @"name";
       private static string   strTypeXPath = @"type";
       private static string   strXmlSpaceXPath = @"space";
       private static string strXmlSpaceNS = @"http://www.w3.org/XML/1998/namespace";
       private static string   strMimeTypeXPath = @"mimetype";
       private static string   strValueXPath = @"./value";
       private static string   strCommentXPath = @"./Comment";
       private static string   strAliasXPath = @"alias";


       static public void SetApplicationRootDirectory(string ApplicationName, string RootDirectoryName)
       {
           try
           {

               SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
               SqlCommand objComm = new SqlCommand();
              
               objComm.Connection = objConn;
               objComm.CommandType = System.Data.CommandType.StoredProcedure;
               objComm.CommandText = "usp_set_application_root_directory";
               SqlParameter objParameter = new SqlParameter("@ApplicationName", System.Data.SqlDbType.NVarChar, 64);
               objParameter.Value = ApplicationName;
               objComm.Parameters.Add(objParameter);
               objParameter = new SqlParameter("@RootDirectory", System.Data.SqlDbType.NVarChar, 4000);
               objParameter.Value = RootDirectoryName;
               objComm.Parameters.Add(objParameter);
               objConn.Open();
               objComm.ExecuteNonQuery();

               
               objConn.Close();

               


           }
           catch (Exception e)
           {
               throw e;

           }
       }
       static public string GetApplicationRootDirectory(string ApplicationName)
       {
           try
           {

               SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
               SqlCommand objComm = new SqlCommand();
              
               objComm.Connection = objConn;
               objComm.CommandType = System.Data.CommandType.StoredProcedure;
               objComm.CommandText = "usp_get_application_root_directory";
               SqlParameter objParameter = new SqlParameter("@ApplicationName", System.Data.SqlDbType.NVarChar, 64);
               objParameter.Value = ApplicationName;
               objComm.Parameters.Add(objParameter);
               objParameter = new SqlParameter("@RootDirectory", System.Data.SqlDbType.NVarChar, 4000);
               objParameter.Direction = System.Data.ParameterDirection.Output;
               objComm.Parameters.Add(objParameter);
               objConn.Open();
               objComm.ExecuteNonQuery();

             
               objConn.Close();

               return Convert.ToString(objComm.Parameters["@RootDirectory"].Value);


           }
           catch (Exception e)
           {
               throw e;

           }
       }
        
        static public ArrayList GetApplicationCultureMasterFileElementList(string ApplicationName, string CultureName)
        {
            try
            {

                SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                SqlCommand objComm = new SqlCommand();
                SqlDataReader objdr;
                ArrayList Elements;

                objComm.Connection = objConn;
                objComm.CommandType = System.Data.CommandType.StoredProcedure;
                objComm.CommandText = "usp_get_master_resx_file_values";
                SqlParameter objParameter = new SqlParameter("@ApplicationName", System.Data.SqlDbType.NVarChar, 64);
                objParameter.Value = ApplicationName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@CultureName", System.Data.SqlDbType.NVarChar, 30);
                objParameter.Value = CultureName;
                objComm.Parameters.Add(objParameter);
                objConn.Open();
                objdr = objComm.ExecuteReader();

                Elements = new ArrayList();


                while (objdr.Read())
                {
                    Elements.Add(new ResxFileElement(objdr.GetString(0), objdr.GetString(1), objdr.GetString(2), objdr.GetString(3), objdr.GetString(4), objdr.GetString(5), "", ResxFileElementType.Data));

                }

                objdr.Close();
                objConn.Close();
                return Elements;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        
        static public ArrayList GetApplicationCultureFileElementList(string ApplicationName, string CultureName, string FileName, ResxFileElementType ElementType)
        {
            try
            {
                
                SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                SqlCommand objComm = new SqlCommand();
                SqlDataReader objdr;
                ArrayList Elements;
               
                objComm.Connection = objConn;
                objComm.CommandType = System.Data.CommandType.StoredProcedure;
                objComm.CommandText = "usp_get_resx_file_values";
                SqlParameter objParameter = new SqlParameter("@ApplicationName", System.Data.SqlDbType.NVarChar, 64);
                objParameter.Value = ApplicationName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@CultureName", System.Data.SqlDbType.NVarChar, 30);
                objParameter.Value = CultureName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@DataSourceName", System.Data.SqlDbType.NVarChar, 1024);
                objParameter.Value = FileName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@ElementType", System.Data.SqlDbType.Int);
                objParameter.Value = ElementType;
                objComm.Parameters.Add(objParameter);
                objConn.Open();
                objdr = objComm.ExecuteReader();

                Elements = new ArrayList(); 
                
                 
                while (objdr.Read())
                {
                   Elements.Add(new ResxFileElement(objdr.GetString(0), objdr.GetString(1), objdr.GetString(2), objdr.GetString(3), objdr.GetString(4), objdr.GetString(5), objdr.GetString(7),ElementType));   
                       
                 }

                objdr.Close();
                objConn.Close();
                return Elements;
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        /// <summary>
        /// Get a list of elements after the last updated date
        /// </summary>
        /// <param name="ApplicationName"></param>
        /// <param name="CultureName"></param>
        /// <param name="lastUpdatedDate"></param>
        /// <returns></returns>
        private static ArrayList GetApplicationCultureMasterFileElementList(object ApplicationName, object CultureName, DateTime lastUpdatedDate)
        {
            try
            {

                SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                SqlCommand objComm = new SqlCommand();
                SqlDataReader objdr;
                ArrayList Elements;

                objComm.Connection = objConn;
                objComm.CommandType = System.Data.CommandType.StoredProcedure;
                objComm.CommandText = "usp_get_master_resx_file_values_updated";
                SqlParameter objParameter = new SqlParameter("@ApplicationName", System.Data.SqlDbType.NVarChar, 64);
                objParameter.Value = ApplicationName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@CultureName", System.Data.SqlDbType.NVarChar, 30);
                objParameter.Value = CultureName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@LastUpdatedDate", System.Data.SqlDbType.DateTime);
                objParameter.Value = lastUpdatedDate;
                objComm.Parameters.Add(objParameter);
                objConn.Open();
                objdr = objComm.ExecuteReader();

                Elements = new ArrayList();


                while (objdr.Read())
                {
                    Elements.Add(new ResxFileElement(objdr.GetString(0), objdr.GetString(1), objdr.GetString(2), objdr.GetString(3), objdr.GetString(4), objdr.GetString(5), "", ResxFileElementType.Data));

                }

                objdr.Close();
                objConn.Close();
                return Elements;
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        static public DataTable GetApplicationNonCultureList(string ApplicationName)
        {
            try
            {

                SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                SqlCommand objComm = new SqlCommand();
                SqlDataReader objdr;
                DataTable ApplicationCultures = new DataTable();
                objComm.Connection = objConn;
                objComm.CommandType = System.Data.CommandType.StoredProcedure;
                objComm.CommandText = "usp_get_application_non_culture_list";
                SqlParameter objParameter = new SqlParameter("@ApplicationName", System.Data.SqlDbType.NVarChar, 64);
                objParameter.Value = ApplicationName;
                objComm.Parameters.Add(objParameter);

                ApplicationCultures.Columns.Add("CultureID", typeof(Int32));
                ApplicationCultures.Columns.Add("CultureName", typeof(String));

                objConn.Open();
                objdr = objComm.ExecuteReader();

                while (objdr.Read())
                {
                    DataRow objdrow = ApplicationCultures.NewRow();
                    objdrow[0] = objdr.GetInt32(0);
                    objdrow[1] = objdr.GetString(1);
                    ApplicationCultures.Rows.Add(objdrow);
                }
                objdr.Close();
                objConn.Close();

                return ApplicationCultures;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        static public DataTable GetApplicationCultureList(string ApplicationName)
        {
            try
            {

                SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                SqlCommand objComm = new SqlCommand();
                SqlDataReader objdr;
                DataTable ApplicationCultures = new DataTable();
                objComm.Connection = objConn;
                objComm.CommandType = System.Data.CommandType.StoredProcedure;
                objComm.CommandText = "usp_get_application_culture_list";
                SqlParameter objParameter = new SqlParameter("@ApplicationName", System.Data.SqlDbType.NVarChar, 64);
                objParameter.Value = ApplicationName;
                objComm.Parameters.Add(objParameter);

                ApplicationCultures.Columns.Add("CultureID", typeof(Int32));
                ApplicationCultures.Columns.Add("CultureName", typeof(String));

                objConn.Open();
                objdr = objComm.ExecuteReader();

                while (objdr.Read())
                {
                    DataRow objdrow = ApplicationCultures.NewRow();
                    objdrow[0] = objdr.GetInt32(0);
                    objdrow[1] = objdr.GetString(1);
                    ApplicationCultures.Rows.Add(objdrow);
                }
                objdr.Close();
                objConn.Close();

                return ApplicationCultures;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        
        static public DataTable GetApplicationFileList(string ApplicationName)
        {
            try
            {

                SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                SqlCommand objComm = new SqlCommand();
                SqlDataReader objdr;
                DataTable ApplicationFiles = new DataTable();
                objComm.Connection = objConn;
                objComm.CommandType = System.Data.CommandType.StoredProcedure;
                objComm.CommandText = "usp_get_application_file_list";
                SqlParameter objParameter = new SqlParameter("@ApplicationName", System.Data.SqlDbType.NVarChar, 64);
                objParameter.Value = ApplicationName;
                objComm.Parameters.Add(objParameter);

                ApplicationFiles.Columns.Add("DataSourceID", typeof(Int32));
                ApplicationFiles.Columns.Add("DataSourceName", typeof(String));

                objConn.Open();
                objdr = objComm.ExecuteReader();

                while (objdr.Read())
                {
                    DataRow objdrow = ApplicationFiles.NewRow();
                    objdrow[0] = objdr.GetInt32(0);
                    objdrow[1] = objdr.GetString(1);
                    ApplicationFiles.Rows.Add(objdrow);
                }
                objdr.Close();
                objConn.Close();

                return ApplicationFiles;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        static public DataTable GetApplicationList()
        {
            try
            {

                SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                SqlCommand objComm = new SqlCommand();
                SqlDataReader objdr;
                DataTable Applications = new DataTable();
                objComm.Connection = objConn;
                objComm.CommandType = System.Data.CommandType.StoredProcedure;
                objComm.CommandText = "usp_get_application_list";

                Applications.Columns.Add("ApplicationID", typeof(Int32));
                Applications.Columns.Add("ApplicationName", typeof(String));

                objConn.Open();
                objdr = objComm.ExecuteReader();

                while (objdr.Read())
                {
                    DataRow objdrow = Applications.NewRow();
                    objdrow[0] = objdr.GetInt32(0);
                    objdrow[1] = objdr.GetString(1);
                    Applications.Rows.Add(objdrow);
                }
                objdr.Close();
                objConn.Close();

                return Applications;
            }
            catch (Exception e)
            {
                throw e;

            }
        }
        static public string GetResxFileText(string ApplicationName, string CultureName,string DataSourceName,int Build)
        {
            try
            {

                SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                SqlCommand objComm = new SqlCommand();
                SqlDataReader objdr;
                string ResxFileText = "";
                objComm.Connection = objConn;
                objComm.CommandType = System.Data.CommandType.StoredProcedure;
                objComm.CommandText = "usp_get_resx_file_text";
                SqlParameter objParameter = new SqlParameter("@ApplicationName", System.Data.SqlDbType.NVarChar, 64);
                objParameter.Value = ApplicationName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@DataSourceName", System.Data.SqlDbType.NVarChar, 400);
                objParameter.Value = DataSourceName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@CultureName", System.Data.SqlDbType.NVarChar, 30);
                objParameter.Value = CultureName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@Build", System.Data.SqlDbType.Int);
                objParameter.Value = Build;
                objComm.Parameters.Add(objParameter);
                objConn.Open();
                objdr = objComm.ExecuteReader();

                if (objdr.Read())
                {
                    ResxFileText = (string)objdr.GetValue(0);

                }

                objdr.Close();
                objConn.Close();

                return ResxFileText;

                
            }
            catch (Exception e)
            {
                throw e;

            }
        }


        static public DataTable GetResxFileHistoryList()
        {
            try
            {

                SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                SqlCommand objComm = new SqlCommand();
                SqlDataReader objdr;
                DataTable ResxFileList = new DataTable();
                objComm.Connection = objConn;
                objComm.CommandType = System.Data.CommandType.StoredProcedure;
                objComm.CommandText = "usp_get_resx_file_versions";


                ResxFileList.Columns.Add("ApplicationName", typeof(String));
                ResxFileList.Columns.Add("CultureName", typeof(String));
                ResxFileList.Columns.Add("DataSourceName", typeof(String));
                ResxFileList.Columns.Add("Build", typeof(int));
                ResxFileList.Columns.Add("Created", typeof(DateTime));

               
                objConn.Open();
                objdr = objComm.ExecuteReader();
                
                while (objdr.Read())
                {
                    DataRow objdrow = ResxFileList.NewRow();
                    objdrow[0] = objdr.GetString(0);
                    objdrow[1] = objdr.GetString(1);
                    objdrow[2] = objdr.GetString(2);
                    objdrow[3] = objdr.GetInt32(3);
                    objdrow[4] = objdr.GetDateTime(4);
                    ResxFileList.Rows.Add(objdrow);    
                }
                objdr.Close();
                objConn.Close();

                return ResxFileList;
            }
            catch (Exception e)
            {
                throw e;
                
            }

   
        }

        static public void CreateNewResxVersion(string ApplicationName, string CultureName, string DataSourceName, string Text)
        {
            try
            {

                SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                SqlCommand objComm = new SqlCommand();
                objComm.Connection = objConn;
                objComm.CommandType = System.Data.CommandType.StoredProcedure;
                objComm.CommandText = "usp_create_new_resxversion";
                SqlParameter objParameter = new SqlParameter("@ApplicationName", System.Data.SqlDbType.NVarChar, 64);
                objParameter.Value = ApplicationName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@DataSourceName", System.Data.SqlDbType.NVarChar, 400);
                objParameter.Value = DataSourceName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@CultureName", System.Data.SqlDbType.NVarChar, 30);
                objParameter.Value = CultureName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@Text", System.Data.SqlDbType.Xml);
                objParameter.Value=new System.Data.SqlTypes.SqlXml(new XmlTextReader(Text, XmlNodeType.Document, null));
                objComm.Parameters.Add(objParameter);
                objConn.Open();
                objComm.ExecuteNonQuery();
                objConn.Close();

                
            }
            catch (Exception e)
            {
                throw e;

            }
        }
        
        static public Boolean CreateNewCultureProperty(string ApplicationName, string CultureName, string DataSourceName, string ElementKey, string PropertyValue, string Comments)
        {
            try
            {

                SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                SqlCommand objComm = new SqlCommand();
                objComm.Connection = objConn;
                objComm.CommandType = System.Data.CommandType.StoredProcedure;
                objComm.CommandText = "usp_create_new_cultureproperty";
                SqlParameter objParameter = new SqlParameter("@ApplicationName", System.Data.SqlDbType.NVarChar, 64);
                objParameter.Value = ApplicationName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@DataSourceName", System.Data.SqlDbType.NVarChar, 400);
                objParameter.Value = DataSourceName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@ElementKey", System.Data.SqlDbType.NVarChar, 128);
                objParameter.Value = ElementKey;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@PropertyValue", System.Data.SqlDbType.NVarChar, 1024);
                objParameter.Value = PropertyValue;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@CultureName", System.Data.SqlDbType.NVarChar, 30);
                objParameter.Value = CultureName;
                objComm.Parameters.Add(objParameter);
                if (Comments != null && Comments != "")
                {
                    objParameter = new SqlParameter("@Comments", System.Data.SqlDbType.NVarChar, 1024);
                    objParameter.Value = Comments;
                    objComm.Parameters.Add(objParameter);
                }
                
                    
                objParameter = new SqlParameter("@Created", System.Data.SqlDbType.Bit);
                objParameter.Direction = System.Data.ParameterDirection.Output;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@Updated", System.Data.SqlDbType.Bit);
                objParameter.Direction = System.Data.ParameterDirection.Output;
                objComm.Parameters.Add(objParameter);
                objConn.Open();
                objComm.ExecuteNonQuery();
                objConn.Close();

                return Convert.ToBoolean(objComm.Parameters["@Created"].Value) && Convert.ToBoolean(objComm.Parameters["@Updated"].Value);
            }
            catch (Exception e)
            {
                 throw e;
                
            }
        }
        static public Boolean CreateNewElement(string ApplicationName, string DataSourceName, string ElementKey, string Description,int ElementType, string Type, string MimeType, string Alias,string XmlSpace)
        {
            try
            {

                SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                SqlCommand objComm = new SqlCommand();
                objComm.Connection = objConn;
                objComm.CommandType = System.Data.CommandType.StoredProcedure;
                objComm.CommandText = "usp_create_new_element";
                SqlParameter objParameter = new SqlParameter("@ApplicationName", System.Data.SqlDbType.NVarChar, 64);
                objParameter.Value = ApplicationName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@DataSourceName", System.Data.SqlDbType.NVarChar, 400);
                objParameter.Value = DataSourceName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@ElementKey", System.Data.SqlDbType.NVarChar, 128);
                objParameter.Value = ElementKey;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@Description", System.Data.SqlDbType.NVarChar, 1024);
                objParameter.Value = Description;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@ElementType", System.Data.SqlDbType.Int);
                objParameter.Value = ElementType;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@Created", System.Data.SqlDbType.Bit);
                objParameter.Direction = System.Data.ParameterDirection.Output;
                objComm.Parameters.Add(objParameter);
                if (Type != null && Type != "")
                {
                    objParameter = new SqlParameter("@Type", System.Data.SqlDbType.NVarChar, 1024);
                    objParameter.Value = Type;
                    objComm.Parameters.Add(objParameter);
                }
                if (MimeType != null && MimeType != "")
                {
                    objParameter = new SqlParameter("@MimeType", System.Data.SqlDbType.NVarChar, 1024);
                    objParameter.Value = MimeType;
                    objComm.Parameters.Add(objParameter);
                }
                if (Alias != null && Alias != "")
                {
                    objParameter = new SqlParameter("@Alias", System.Data.SqlDbType.NVarChar, 1024);
                    objParameter.Value = Alias;
                    objComm.Parameters.Add(objParameter);
                }

                if (XmlSpace != null && XmlSpace != "")
                {
                    objParameter = new SqlParameter("@XmlSpace", System.Data.SqlDbType.NVarChar, 4000);
                    objParameter.Value = XmlSpace;
                    objComm.Parameters.Add(objParameter);
                }

                objConn.Open();
                objComm.ExecuteNonQuery();
                objConn.Close();

                return Convert.ToBoolean(objComm.Parameters["@Created"].Value);
            }
            catch (Exception e)
            {
                throw e;
                
            }

        }
        static public Boolean CreateNewDataSource(string ApplicationName, string DataSourceName, string DataSourceDescription,int Locked)
        {
            try
            {

                SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                SqlCommand objComm = new SqlCommand();
                objComm.Connection = objConn;
                objComm.CommandType = System.Data.CommandType.StoredProcedure;
                objComm.CommandText = "usp_create_new_datasource";
                SqlParameter objParameter = new SqlParameter("@ApplicationName", System.Data.SqlDbType.NVarChar, 64);
                objParameter.Value = ApplicationName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@DataSourceName", System.Data.SqlDbType.NVarChar, 400);
                objParameter.Value = DataSourceName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@DataSourceDescription", System.Data.SqlDbType.NVarChar, 255);
                objParameter.Value = DataSourceDescription;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@Locked", System.Data.SqlDbType.Bit);
                objParameter.Value = Locked;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@Created", System.Data.SqlDbType.Bit);
                objParameter.Direction = System.Data.ParameterDirection.Output;
                objComm.Parameters.Add(objParameter);

                objConn.Open();
                objComm.ExecuteNonQuery();
                objConn.Close();

                return Convert.ToBoolean(objComm.Parameters["@Created"].Value);
            }
            catch (Exception e)
            {
                throw e;
                
            }

        }
        
        static public Boolean CreateNewApplicationCulture(string ApplicationName,string CultureName)
        {
            try
            {

                SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                SqlCommand objComm = new SqlCommand();
                objComm.Connection = objConn;
                objComm.CommandType = System.Data.CommandType.StoredProcedure;
                objComm.CommandText = "usp_create_new_applicationculture";
                SqlParameter objParameter = new SqlParameter("@ApplicationName", System.Data.SqlDbType.NVarChar, 64);
                objParameter.Value = ApplicationName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@CultureName", System.Data.SqlDbType.NVarChar, 30);
                objParameter.Value = CultureName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@Created", System.Data.SqlDbType.Bit);
                objParameter.Direction = System.Data.ParameterDirection.Output;
                objComm.Parameters.Add(objParameter);

                objConn.Open();
                objComm.ExecuteNonQuery();
                objConn.Close();

                return Convert.ToBoolean(objComm.Parameters["@Created"].Value);
            }
            catch (Exception e)
            {
                throw e;
                
            }

        }

        static public void DeleteApplicationCulture(string ApplicationName, string CultureName)
        {
            try
            {

                SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                SqlCommand objComm = new SqlCommand();
                objComm.Connection = objConn;
                objComm.CommandType = System.Data.CommandType.StoredProcedure;
                objComm.CommandText = "usp_delete_applicationculture";
                SqlParameter objParameter = new SqlParameter("@ApplicationName", System.Data.SqlDbType.NVarChar, 64);
                objParameter.Value = ApplicationName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@CultureName", System.Data.SqlDbType.NVarChar, 30);
                objParameter.Value = CultureName;
                objComm.Parameters.Add(objParameter);
                objConn.Open();
                objComm.ExecuteNonQuery();
                objConn.Close();

               
            }
            catch (Exception e)
            {
                throw e;

            }

        }
        
        static public Boolean CreateNewApplication(String ApplicationName, String ApplicationDescription, String DefaultBaseName, int Build, int MajorVersion, int MinorVersion, int Locked)
        {
            try
            {
                
                SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                SqlCommand objComm = new SqlCommand();
                objComm.Connection = objConn;
                objComm.CommandType = System.Data.CommandType.StoredProcedure;
                objComm.CommandText="usp_create_new_application"; 
                SqlParameter objParameter = new SqlParameter("@ApplicationName", System.Data.SqlDbType.NVarChar, 64);
                objParameter.Value = ApplicationName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@ApplicationDescription", System.Data.SqlDbType.NVarChar, 255);
                objParameter.Value = ApplicationDescription;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@DefaultBaseName", System.Data.SqlDbType.NVarChar, 64);
                objParameter.Value = DefaultBaseName;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@Build", System.Data.SqlDbType.Int);
                objParameter.Value =Build;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@MajorVersion", System.Data.SqlDbType.Int);
                objParameter.Value = MajorVersion;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@MinorVersion", System.Data.SqlDbType.Int);
                objParameter.Value = MinorVersion;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@Locked", System.Data.SqlDbType.Bit);
                objParameter.Value = Locked;
                objComm.Parameters.Add(objParameter);
                objParameter = new SqlParameter("@Created", System.Data.SqlDbType.Bit);
                objParameter.Direction = System.Data.ParameterDirection.Output;    
                objComm.Parameters.Add(objParameter);

                objConn.Open();
                objComm.ExecuteNonQuery();
                objConn.Close();

                return Convert.ToBoolean(objComm.Parameters["@Created"].Value);  
            }
            catch (Exception e)
            {
                throw e;
                
            }

        }

        static public FileInfo[]GetResxFiles(string Path, string Pattern)
        {
            try
            {
                DirectoryInfo diPath;
                FileInfo[] fiPathFiles;
                diPath = new DirectoryInfo(Path);
                fiPathFiles = diPath.GetFiles(Pattern, SearchOption.AllDirectories);
                return fiPathFiles; 
            }
            catch (Exception e)
            {
                throw e;
                
            }
        }

        
        
        static public ResxFileElement[] GetResxFileElements(String FileName)
        {
            try
            {
                ResxFileElement[] Elements;
                
                int intCounter = 0;

                
                XPathDocument xpd = new XPathDocument(FileName);
                XPathNavigator xpn = xpd.CreateNavigator(); 
                XPathNodeIterator xpni = xpn.Select(strDataElementsXPath);
                XPathNodeIterator xpni2 = xpn.Select(strMetaDataElementsXPath);
                XPathNodeIterator xpni3 = xpn.Select(strResHeaderElementsXPath);
                XPathNodeIterator xpni4 = xpn.Select(strAssemblyElementsXPath);

                //data elements
                Elements = new ResxFileElement[xpni.Count + xpni2.Count + xpni3.Count + xpni4.Count];   
                
                while (xpni.MoveNext())
                {
                    Elements[intCounter] = ElementData(xpni,ResxFileElementType.Data);  
                    intCounter++;
                    
                }

                while (xpni2.MoveNext())
                {
                    Elements[intCounter] = ElementData(xpni2, ResxFileElementType.MetaData);
                    intCounter++;

                }

                while (xpni3.MoveNext())
                {
                    Elements[intCounter] = ElementData(xpni3, ResxFileElementType.ResHeader);
                    intCounter++;

                }

                while (xpni4.MoveNext())
                {
                    Elements[intCounter] = ElementData(xpni4, ResxFileElementType.Assembly);
                    intCounter++;

                }

                return Elements;


 
            }
            catch (Exception e)
            {
                throw e;
                
            }
            
          }

        static public ResxFileElement ElementData(System.Xml.XPath.XPathNodeIterator xpni, ResxFileElementType ElementType)
        {
            try
            {
                string strName;
                string strValue;
                string strComment;
                string strType;
                string strMimeType;
                string strAlias;
                string strXmlSpace;

                strName = RemoveXMLCharacters(xpni.Current.GetAttribute(strNameXPath, ""));


                if (xpni.Current.GetAttribute(strXmlSpaceXPath, strXmlSpaceNS) != null)
                {
                    strXmlSpace = RemoveXMLCharacters(xpni.Current.GetAttribute(strXmlSpaceXPath, strXmlSpaceNS));

                }
                else
                {
                    strXmlSpace = null;
                }
                
                if (xpni.Current.GetAttribute(strTypeXPath, "") != null)
                {
                    strType = RemoveXMLCharacters(xpni.Current.GetAttribute(strTypeXPath, ""));

                }
                else
                {
                    strType = null;
                }

                if (xpni.Current.GetAttribute(strMimeTypeXPath, "") != null)
                {
                    strMimeType = RemoveXMLCharacters(xpni.Current.GetAttribute(strMimeTypeXPath, ""));

                }
                else
                {
                    strMimeType = null;
                }

                if (xpni.Current.GetAttribute(strAliasXPath, "") != null)
                {
                    strAlias = RemoveXMLCharacters(xpni.Current.GetAttribute(strAliasXPath, ""));

                }
                else
                {
                    strAlias = null;
                }

                if (xpni.Current.SelectSingleNode(strValueXPath) != null)
                {
                    strValue = RemoveXMLCharacters(xpni.Current.SelectSingleNode(strValueXPath).InnerXml);
                }
                else
                {
                    strValue = null;
                }
                if (xpni.Current.SelectSingleNode(strCommentXPath) != null)
                {
                    strComment = RemoveXMLCharacters(xpni.Current.SelectSingleNode(strCommentXPath).InnerXml);
                }
                else
                {
                    strComment = null;
                }
                
                return new ResxFileElement(strName, strValue, strComment, strType, strMimeType, strAlias,strXmlSpace,ElementType);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        static public void ImportMasterResxFiles(string ApplicationName, string Directory)
        {
            try
            {
                
                FileInfo[] fiResxFiles;

                fiResxFiles = Utilities.GetResxFiles(Directory, ApplicationName + @"*.resx");

                foreach (FileInfo fiTemp in fiResxFiles)
                {
                    ResxFileElement[] Elements;
                    String[] SplitFileName;
                    String CultureName;
                    String FileName;
                    String ElementName;
                    SplitFileName = fiTemp.Name.Split('.');
                    
                   if (SplitFileName[1] == "resx")
                    {
                            CultureName = "inv";
                            
                   }
                   else
                   {

                        CultureName = SplitFileName[1];
                    }
                    Elements = Utilities.GetResxFileElements(fiTemp.FullName);



                    foreach (ResxFileElement rfeTemp in Elements)
                    {
                        
                        ElementName = rfeTemp.Name.Substring(rfeTemp.Name.IndexOf(".resx") + 6);
                        FileName = rfeTemp.Name.Substring(0, rfeTemp.Name.IndexOf(".resx")+5);

                        if (rfeTemp.Value != null && rfeTemp.Value != String.Empty && rfeTemp.ElementType == ResxFileElementType.Data)
                        {
                            Utilities.CreateNewCultureProperty(ApplicationName, CultureName, FileName, ElementName, rfeTemp.Value, rfeTemp.Comment);
                        }
                        
                    }

                 }

            }
            
            catch (Exception e)
            {
                throw e;
            }
        }
        static public void ImportResxFiles(String ApplicationName, String Directory)
        {
            try
            {

                FileInfo[] fiResxFiles;
              
               fiResxFiles = Utilities.GetResxFiles(Directory, @"*.resx");


                foreach (FileInfo fiTemp in fiResxFiles)
                {
                    ResxFileElement[] Elements;
                    String[] SplitFileName;
                    String CultureName;
                    String FileName;
                    String FileNameDirectory;
                    SplitFileName = fiTemp.Name.Split('.');
                    FileNameDirectory = fiTemp.DirectoryName.Substring(Directory.Length) ;
 
                    //local
                    if (fiTemp.Name.IndexOf(".ascx") > 0 || fiTemp.Name.IndexOf(".aspx") > 0 || fiTemp.Name.IndexOf(".master") > 0)
                    {

                        if (SplitFileName[2] == "resx")
                        {

                            CultureName = "inv";
                            FileName = FileNameDirectory + @"\" + SplitFileName[0] + "." + SplitFileName[1] + "." + SplitFileName[2];

                        }
                        else
                        {


                            CultureName = SplitFileName[2];
                            FileName = FileNameDirectory + @"\" + SplitFileName[0] + "." + SplitFileName[1] + "." + SplitFileName[3];

                        }

                    }
                    //global
                    else
                    {

                        if (SplitFileName[1] == "resx")
                        {
                            CultureName = "inv";
                            FileName = FileNameDirectory + @"\" + SplitFileName[0] + "." + SplitFileName[1];
                        }
                        else
                        {


                            CultureName = SplitFileName[1];
                            FileName = FileNameDirectory + @"\" + SplitFileName[0] + "." + SplitFileName[2];

                        }

                    }
                    Utilities.CreateNewApplicationCulture(ApplicationName, CultureName);
                    Utilities.CreateNewDataSource(ApplicationName, FileName, FileName, 0);

                    Elements = Utilities.GetResxFileElements(fiTemp.FullName);



                    foreach (ResxFileElement rfeTemp in Elements)
                    {
                        Utilities.CreateNewElement(ApplicationName, FileName, rfeTemp.Name, rfeTemp.Name,System.Convert.ToInt32(rfeTemp.ElementType), rfeTemp.Type,rfeTemp.MimeType,rfeTemp.Alias,rfeTemp.XmlSpace);
                        Utilities.CreateNewCultureProperty(ApplicationName, CultureName, FileName, rfeTemp.Name, rfeTemp.Value, rfeTemp.Comment);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            
        }

        static public void ExportVersionedResxFile(string ApplicationName, string CultureName, string DataSourceName, int Build, string FileName)
        {
            try
            {
                string ResxFileText;
                ResxFileText = GetResxFileText(ApplicationName, CultureName, DataSourceName, Build);
                //write file to disk
                StreamWriter sw;
                sw = new StreamWriter(FileName, false);
                sw.Write(ResxFileText);
                sw.Flush();
                sw.Close();
   
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        static public void ExportResxFile(string ApplicationName, string CultureName,string FileName, string DirectoryName)
        {
            try
            {

                ArrayList ResHeaderElements;
                ArrayList DataElements;
                ArrayList AssemblyElements;
                ArrayList MetaDataElements;
                StringBuilder objsb = new StringBuilder();
                string strFileName;
                int ResHeaderCount = 0;
                int ElementCount = 0;
                objsb.Append(GetResxFileHeader());

                ResHeaderElements = Utilities.GetApplicationCultureFileElementList(ApplicationName, CultureName, FileName, ResxFileElementType.ResHeader);

              
                foreach (ResxFileElement fetemp in ResHeaderElements)
                {
                    if (fetemp.Name != "" && fetemp.Value != "" && fetemp.Name != null && fetemp.Value != null)
                    {
                        objsb.Append("\t" + @"<resheader name=""");
                        objsb.Append(EscapeXMLCharacters(fetemp.Name) + @""">" + "\r\n");
                        objsb.Append("\t\t" + @"<value>" + EscapeXMLCharacters(fetemp.Value) + @"</value>" + "\r\n");
                        objsb.Append("\t" + @"</resheader>" + "\r\n");
                        ResHeaderCount++;
                    }
                }

                if (ResHeaderCount == 0)
                {
                    objsb.Append(GetResxFileResHeaders());  
                }

                DataElements = Utilities.GetApplicationCultureFileElementList(ApplicationName, CultureName, FileName, ResxFileElementType.Data);
                foreach (ResxFileElement fetemp in DataElements)
                {
                    if (fetemp.Name != ""  && fetemp.Name != null )
                    {
                        objsb.Append("\t" + @"<data name=""" + EscapeXMLCharacters(fetemp.Name) + @"""");
                        if (fetemp.XmlSpace != "" && fetemp.XmlSpace != null)
                        {
                            objsb.Append(@" xml:space=""" + EscapeXMLCharacters(fetemp.XmlSpace) + @"""");
                        }
                        if (fetemp.Type != "" && fetemp.Type != null)
                        {
                            objsb.Append(@" type=""" + EscapeXMLCharacters(fetemp.Type) + @"""");
                        }
                        if (fetemp.MimeType != "" && fetemp.MimeType != null)
                        {
                            objsb.Append(@" mimetype=""" + EscapeXMLCharacters(fetemp.MimeType) + @"""");
                        }
                        objsb.Append(@">" + "\r\n");
                        objsb.Append("\t\t" + @"<value>" + EscapeXMLCharacters(fetemp.Value) + @"</value>" + "\r\n");
                        if (fetemp.Comment != "" && fetemp.Comment != null)
                        {
                            objsb.Append("\t\t" + @"<comment>" + EscapeXMLCharacters(fetemp.Comment) + @"</comment>" + "\r\n");
                        }
                        objsb.Append("\t" + @"</data>" + "\r\n");
                        ElementCount++; 
                    }

                }

                AssemblyElements = Utilities.GetApplicationCultureFileElementList(ApplicationName, CultureName, FileName, ResxFileElementType.Assembly);
                foreach (ResxFileElement fetemp in AssemblyElements)
                {
                    if (fetemp.Name != "" && fetemp.Alias != "" && fetemp.Name != null && fetemp.Alias != null)
                    {
                        objsb.Append("\t" + @"<assembly name=""" + EscapeXMLCharacters(fetemp.Name) + @"""");
                        objsb.Append(@" alias=""" + EscapeXMLCharacters(fetemp.Alias) + @"""");
                        objsb.Append(@">" + "\r\n");
                        objsb.Append("\t" + @"</assembly>" + "\r\n");
                        ElementCount++; 
                    }
                }

                MetaDataElements = Utilities.GetApplicationCultureFileElementList(ApplicationName, CultureName, FileName, ResxFileElementType.MetaData);
                foreach (ResxFileElement fetemp in MetaDataElements)
                {
                    if (fetemp.Name != "" && fetemp.Value != "" && fetemp.Name != null && fetemp.Value != null)
                    {
                        objsb.Append("\t" + @"<metadata name=""" + EscapeXMLCharacters(fetemp.Name) + @"""");
                        if (fetemp.Type != "" && fetemp.Type != null)
                        {
                            objsb.Append(@" type=""" + EscapeXMLCharacters(fetemp.Type) + @"""");
                        }
                        if (fetemp.MimeType != "" && fetemp.MimeType != null)
                        {
                            objsb.Append(@" mimetype=""" + EscapeXMLCharacters(fetemp.MimeType) + @"""");
                        }
                        objsb.Append(@">" + "\r\n");
                        objsb.Append("\t\t" + @"<value>" + EscapeXMLCharacters(fetemp.Value) + @"</value>" + "\r\n");

                        objsb.Append("\t" + @"</metadata>" + "\r\n");
                        ElementCount++; 
                    }

                }

                objsb.Append(GetResxFileFooter());

                if (CultureName == "inv")
                {
                    strFileName = FileName;
                }
                else
                {
                    strFileName = FileName.Substring(0, FileName.Length - 5) + "." + CultureName + FileName.Substring(FileName.Length - 5);
                }
                
                
                    StreamWriter sw;
                    sw = new StreamWriter(DirectoryName + strFileName, false);
                    sw.Write(objsb.ToString());
                    sw.Flush();
                    sw.Close();
                    Utilities.CreateNewResxVersion(ApplicationName, CultureName, FileName, objsb.ToString());
                
            }
            catch (Exception e)
            {
                throw e;
            }

        }

        static public void ExportMasterResxFile(string ApplicationName, string CultureName, string FileName)
        {
            try
            {   
                StringBuilder objsb = new StringBuilder();
                objsb.Append(GetResxFileHeader());
                objsb.Append(GetResxFileResHeaders());
                ArrayList DataElements;
                DataElements = Utilities.GetApplicationCultureMasterFileElementList(ApplicationName, CultureName);

                foreach (ResxFileElement fetemp in DataElements)
                {
                   
                        objsb.Append("\t" + @"<data name=""" + EscapeXMLCharacters(fetemp.Name) + @"""");
                        //objsb.Append(@" type=""" + EscapeXMLCharacters(fetemp.Type) + @"""");
                        //objsb.Append(@" mimetype=""" + EscapeXMLCharacters(fetemp.MimeType) + @"""");
                        objsb.Append(@">" + "\r\n");
                        objsb.Append("\t\t" + @"<value>" + EscapeXMLCharacters(fetemp.Value) + @"</value>" + "\r\n");
                        objsb.Append("\t\t" + @"<comment>" + EscapeXMLCharacters(fetemp.Comment) + @"</comment>" + "\r\n");
                        objsb.Append("\t" + @"</data>" + "\r\n");
                    

                }
                objsb.Append(GetResxFileFooter());
                StreamWriter sw;
                sw = new StreamWriter(FileName, false);
                sw.Write(objsb.ToString());
                sw.Flush();
                sw.Close();
                
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        /// <summary>
        /// Exports data updated after the given lastUpdatedDate as a master resx file
        /// </summary>
        /// <param name="strApplicationName"></param>
        /// <param name="strCultureName"></param>
        /// <param name="strFileName"></param>
        /// <param name="lastUpdatedDate"></param>
        public static void ExportMasterDiffResxFile(string strApplicationName, string strCultureName, string strFileName, DateTime lastUpdatedDate, string FileName)
        {
            try
            {
                StringBuilder objsb = new StringBuilder();
                objsb.Append(GetResxFileHeader());
                objsb.Append(GetResxFileResHeaders());
                ArrayList DataElements;
                DataElements = Utilities.GetApplicationCultureMasterFileElementList(strApplicationName, strCultureName, lastUpdatedDate);

                foreach (ResxFileElement fetemp in DataElements)
                {

                    objsb.Append("\t" + @"<data name=""" + EscapeXMLCharacters(fetemp.Name) + @"""");
                    //objsb.Append(@" type=""" + EscapeXMLCharacters(fetemp.Type) + @"""");
                    //objsb.Append(@" mimetype=""" + EscapeXMLCharacters(fetemp.MimeType) + @"""");
                    objsb.Append(@">" + "\r\n");
                    objsb.Append("\t\t" + @"<value>" + EscapeXMLCharacters(fetemp.Value) + @"</value>" + "\r\n");
                    objsb.Append("\t\t" + @"<comment>" + EscapeXMLCharacters(fetemp.Comment) + @"</comment>" + "\r\n");
                    objsb.Append("\t" + @"</data>" + "\r\n");


                }
                objsb.Append(GetResxFileFooter());
                StreamWriter sw;
                sw = new StreamWriter(FileName, false);
                sw.Write(objsb.ToString());
                sw.Flush();
                sw.Close();

            }
            catch (Exception e)
            {
                throw e;
            }
        }

        static public string RemoveXMLCharacters(string strXML)
        {
            if (strXML != null)
            {
                return strXML.Replace(@"&amp;", @"&").Replace(@"&lt;", @"<").Replace(@"&gt;", ">").Replace(@"&quot", @"""").Replace(@"&apos", @"'");
            }
            else
            {
                return "";
            }
        }

        static public string EscapeXMLCharacters(string value)
        {
            if (value != null)
            {
                return value.Replace(@"&", "&amp;").Replace(@">", "&gt;").Replace(@"<", "&lt;").Replace(@"""", "&quot;").Replace(@"'", "&apos;");
            }
            else
            {
                return "";
            }


        }
        static public string GetResxFileHeader()
        {
            StringBuilder objsb = new StringBuilder();
            objsb.Append(@"<?xml version=""1.0"" encoding=""utf-8""?>" + "\r\n");
            objsb.Append(@"<root>" + "\r\n");
            objsb.Append("\t" + @"<xsd:schema id=""root"" xmlns="""" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">" + "\r\n");
            objsb.Append("\t\t" + @"<xsd:import namespace=""http://www.w3.org/XML/1998/namespace"" />" + "\r\n");
            objsb.Append("\t\t" + @"<xsd:element name=""root"" msdata:IsDataSet=""true"">" + "\r\n");
            objsb.Append("\t\t\t" + @"<xsd:complexType>" + "\r\n");
            objsb.Append("\t\t\t\t" + @"<xsd:choice maxOccurs=""unbounded"">" + "\r\n");
            objsb.Append("\t\t\t\t\t" + @"<xsd:element name=""metadata"">" + "\r\n");
            objsb.Append("\t\t\t\t\t\t" + @"<xsd:complexType>" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t" + @"<xsd:sequence>" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t\t" + @"<xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" />" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t" + @"</xsd:sequence>" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t" + @"<xsd:attribute name=""name"" use=""required"" type=""xsd:string"" />" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t" + @"<xsd:attribute name=""type"" type=""xsd:string"" />" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t" + @"<xsd:attribute name=""mimetype"" type=""xsd:string"" />" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t" + @"<xsd:attribute ref=""xml:space""/>" + "\r\n");
            objsb.Append("\t\t\t\t\t\t" + @"</xsd:complexType>" + "\r\n");
            objsb.Append("\t\t\t\t\t" + @"</xsd:element>" + "\r\n");
            objsb.Append("\t\t\t\t\t" + @"<xsd:element name=""assembly"">" + "\r\n");
            objsb.Append("\t\t\t\t\t\t" + @"<xsd:complexType>" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t" + @"<xsd:attribute name=""alias"" type=""xsd:string"" />" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t" + @"<xsd:attribute name=""name"" type=""xsd:string"" />" + "\r\n");
            objsb.Append("\t\t\t\t\t\t" + @"</xsd:complexType>" + "\r\n");
            objsb.Append("\t\t\t\t\t" + @"</xsd:element>" + "\r\n");
            objsb.Append("\t\t\t\t\t" + @"<xsd:element name=""data"">" + "\r\n");
            objsb.Append("\t\t\t\t\t\t" + @"<xsd:complexType>" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t" + @"<xsd:sequence>" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t\t" +  @"<xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""1"" />" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t\t" +  @"<xsd:element name=""comment"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""2"" />" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t" + @"</xsd:sequence>" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t" + @"<xsd:attribute name=""name"" type=""xsd:string"" use=""required"" msdata:Ordinal=""1"" />" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t" + @"<xsd:attribute name=""type"" type=""xsd:string"" msdata:Ordinal=""3"" />" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t" + @"<xsd:attribute name=""mimetype"" type=""xsd:string"" msdata:Ordinal=""4"" />" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t" + @"<xsd:attribute ref=""xml:space"" />" + "\r\n");
            objsb.Append("\t\t\t\t\t\t" + @"</xsd:complexType>" + "\r\n");
            objsb.Append("\t\t\t\t\t" + @"</xsd:element>" + "\r\n");
            objsb.Append("\t\t\t\t\t" + @"<xsd:element name=""resheader"">" + "\r\n");
            objsb.Append("\t\t\t\t\t\t" + @"<xsd:complexType>" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t" + @"<xsd:sequence>" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t\t" +@"<xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""1"" />" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t" + @"</xsd:sequence>" + "\r\n");
            objsb.Append("\t\t\t\t\t\t\t" + @"<xsd:attribute name=""name"" type=""xsd:string"" use=""required"" />" + "\r\n");
            objsb.Append("\t\t\t\t\t\t" + @"</xsd:complexType>" + "\r\n");
            objsb.Append("\t\t\t\t\t" + @"</xsd:element>" + "\r\n");
            objsb.Append("\t\t\t\t" + @"</xsd:choice>" + "\r\n");
            objsb.Append("\t\t\t" + @"</xsd:complexType>" + "\r\n");
            objsb.Append("\t\t" + @"</xsd:element>" + "\r\n");
            objsb.Append("\t" + @"</xsd:schema>" + "\r\n");
            //objsb.Append(@"" + "\r\n");
            //objsb.Append(@"" + "\r\n");
            //objsb.Append(@"" + "\r\n");

            return objsb.ToString(); 
        }

        public static string GetResxFileFooter()
        {
            StringBuilder objsb = new StringBuilder();
            objsb.Append(@"</root>");
            return objsb.ToString();
        }
        public static string GetResxFileResHeaders()
        {
            StringBuilder objsb = new StringBuilder();
            objsb.Append("\t" + @"<resheader name=""resmimetype"">"+ "\r\n");
            objsb.Append("\t\t" + @"<value>text/microsoft-resx</value>"+ "\r\n");
            objsb.Append("\t" + @"</resheader>"+ "\r\n");
            objsb.Append("\t" + @"<resheader name=""version"">"+ "\r\n");
            objsb.Append("\t\t" + @"<value>2.0</value>"+ "\r\n");
            objsb.Append("\t" +@"</resheader>" + "\r\n");
            objsb.Append("\t" +@"<resheader name=""reader"">"+ "\r\n");
            objsb.Append("\t\t" +@"<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>"+ "\r\n");
            objsb.Append("\t" + @"</resheader>"+ "\r\n");
            objsb.Append("\t" + @"<resheader name=""writer"">"+ "\r\n");
            objsb.Append("\t\t" +@"<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>"+ "\r\n");
            objsb.Append("\t" +@"</resheader>");
            return objsb.ToString();  
        }
    }
}
